package com.yimi.yinhepda.db.dao;

import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where;
import com.yimi.yinhepda.base.BaseApplication;
import com.yimi.yinhepda.db.helper.DbHelper;
import com.yimi.yinhepda.db.table.MoveStockTaskCacheTable;

import java.sql.SQLException;
import java.util.List;

/**
 * @author: lj
 * Date: 2018/12/29
 * Description:移库装卸车暂存表操作类
 */
public class MoveStockTaskCacheTableDao extends BaseDao<MoveStockTaskCacheTable, Long> {

    public MoveStockTaskCacheTableDao() {
        super(DbHelper.getInstance(BaseApplication.getContext()), MoveStockTaskCacheTable.class);
    }

    /**
     * 根据任务号查询
     *
     * @param mTaskNo  任务号
     * @param operType 1-装车，2-卸车
     * @return
     */
    public MoveStockTaskCacheTable findByTaskNo(String mTaskNo, int operType) {
        try {
            QueryBuilder<MoveStockTaskCacheTable, Long> queryBuilder = dao.queryBuilder();
            Where where = queryBuilder.where();
            where.eq("taskNo", mTaskNo);
            where.and().eq("operType", operType);
            return queryBuilder.queryForFirst();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 根据上传状态查询数据
     *
     * @param isUpload 0-未上传，1-已上传
     * @param operType 1-装车，2-卸车
     * @return
     */
    public List<MoveStockTaskCacheTable> findByUpload(int isUpload, int operType) {
        try {
            QueryBuilder<MoveStockTaskCacheTable, Long> queryBuilder = dao.queryBuilder();
            Where where = queryBuilder.where();
            where.eq("isUpload", isUpload);
            where.and().eq("operType", operType);
            return queryBuilder.query();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
